package it.uniparthenope.smartqueue;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.StatusLine;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;

//import com.example.unitime.Login;

import android.content.Context;
import android.content.Intent;
import android.util.Log;

public final class CommonUtilities {
	
	// give your server registration url here
    static final String SERVER_URL = "http://students.uniparthenope.it/~0124000315/progetti/gcm_server_php/register.php"; 

    // Google project id
    static final String SENDER_ID = "629062853696"; 

    /**
     * Tag used on log messages.
     */
    static final String TAG = "AndroidHive GCM";

    static final String DISPLAY_MESSAGE_ACTION =
            "com.androidhive.pushnotifications.DISPLAY_MESSAGE";

    static final String EXTRA_MESSAGE = "message";

    /**
     * Notifies UI to display a message.
     * <p>
     * This method is defined in the common helper because it's used both by
     * the UI and the background service.
     *
     * @param context application's context.
     * @param message message to be displayed.
     */
    static void displayMessage(Context context, String message) {
        Intent intent = new Intent(DISPLAY_MESSAGE_ACTION);
        intent.putExtra(EXTRA_MESSAGE, message);
        context.sendBroadcast(intent);
    }
    
    
    public static String readJSON(String URL) {
    	StringBuilder builder = new StringBuilder();
        HttpClient client = new DefaultHttpClient();
        HttpGet httpGet = new HttpGet(URL);
        try {
        	HttpResponse response = client.execute(httpGet);
        	StatusLine statusLine = response.getStatusLine();
        	int statusCode = statusLine.getStatusCode();
        	if (statusCode == 200) {
        		HttpEntity entity = response.getEntity();
        		InputStream content = entity.getContent();
        		BufferedReader reader = new BufferedReader(new InputStreamReader(content));
        		String line;
        		while ((line = reader.readLine()) != null) {
        			builder.append(line);
        		}
        	} else {
        		//Log.e( Login.class.toString(), "Failed to download file");
        		
        		
        	}
        } catch (ClientProtocolException e) {
        	e.printStackTrace();
        } catch (IOException e) {
        	e.printStackTrace();
        }
        return builder.toString();
    }
    
    
    
   
}
